
package com.ctrip.corp.obt.shard.sql.mybatis.interceptor.dialect;


import com.ctrip.corp.obt.generic.utils.ExceptionUtils;

/**
 * ORACLE 数据库分页语句组装实现
 * 通用分页版本
 *
 * @author marco.zheng
 * @since 2022-03-15
 */
public class OracleDialect implements IDialect {

    @Override
    public PageDialectModel buildPaginationSql(String originalSql, long offset, long limit) {
        limit = (offset >= 1) ? (offset + limit) : limit;
        String sql = "SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( " +
            originalSql + " ) TMP WHERE ROWNUM <=" + FIRST_MARK + ") WHERE ROW_ID > " + SECOND_MARK;
        return new PageDialectModel(sql, limit, offset).setConsumerChain();
    }

    @Override
    public String buildTableSearchSql(String tableName) {
        throw ExceptionUtils.mpe("Do not support now");
    }
}
